package arkham.net.messages;

import java.io.IOException;

public class ErrorMessage extends Message 
{
	private String error;
	
	/**
	 * Creates an error message with an empty string as the text
	 */
	public ErrorMessage()
	{
		error = "";
	}
	
	/**
	 * Creates an error message with the specified text
	 * @param txt The text of the error message
	 */
	public ErrorMessage(String txt)
	{
		this.error = txt;
	}
	
	@Override
	public int getId() {
		return MessageType.ERROR_MESSAGE.id();
	}
	
	
	/**
	 * Gets the text of this message
	 * @return the text
	 */
	public String getText()
	{
		return error;
	}
	
	/**
	 * Sets the text of this message
	 * @param txt The text to set
	 */
	public void setText(String txt)
	{
		this.error = txt;
	}
	
	@Override
	public String toString()
	{
		return error;
	}
	
	/*
	 * (non-Javadoc)
	 * @see arkham.net.Message#toByteArray()
	 */
	public byte[] toByteArray() {
		
		return error.getBytes();
	}
	
	/*
	 * (non-Javadoc)
	 * @see arkham.net.Message#fromByteArray(byte[])
	 */
	public void fromByteArray(byte[] b) throws IOException
	{
		error = new String(b);
	}

}
